/**
 * 
 */

package org.minuframework.aliyun;

import java.io.File;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.minuframework.core.ApplicationConfigurer;
import org.minuframework.file.FileUtils;
import org.minuframework.utils.ParamUtils;
import com.google.common.collect.Maps;

/**
 * 阿里云短信参数类
 * 
 * @author 米mi
 */
public class AliyunDysmsConfigurer {

    /**
     * 前缀
     */
    private static final String prefix = "sms.aliyun";

    private static Map<Object, Object> params = Maps.newHashMap();

    public AliyunDysmsConfigurer() {
        String pathname =
                ParamUtils.getPathName(ApplicationConfigurer.DEFAULT_MINU_CONFIGURER_FILE);
        params = FileUtils.asMap(new File(pathname), pathname);
    }

    public String getProduct() {
        return params.containsKey(getKey("product")) ? params.get(getKey("product")).toString()
                : null;
    }

    public String getDomain() {
        return params.containsKey(getKey("domain")) ? params.get(getKey("domain")).toString()
                : null;
    }

    public String getAccessKeyId() {
        return params.containsKey(getKey("accessKeyId"))
                ? params.get(getKey("accessKeyId")).toString()
                : null;
    }

    public String getAccessKeySecret() {
        return params.containsKey(getKey("accessKeySecret"))
                ? params.get(getKey("accessKeySecret")).toString()
                : null;
    }

    public String getTemplateCode() {
        return params.containsKey(getKey("templateCode"))
                ? params.get(getKey("templateCode")).toString()
                : null;
    }

    public String getSignName() {
        return params.containsKey(getKey("signName")) ? params.get(getKey("signName")).toString()
                : null;
    }

    public String getOutId() {
        return params.containsKey(getKey("outId")) ? params.get(getKey("outId")).toString() : null;
    }

    public Map<Object, Object> getParams() {
        return params;
    }

    public int size() {
        return params.size();
    }

    public String toString() {
        return params.toString();
    }

    private String getKey(String key) {
        return StringUtils.isNotEmpty(key) ? (prefix + '.' + key) : null;
    }

    public static void main(String[] args) {
        AliyunDysmsConfigurer configurer = new AliyunDysmsConfigurer();
        System.out.println(configurer.size());
        System.out.println(configurer.toString());
        System.out.println(configurer.getProduct());
    }
}
